/*
 * Copyright (C) 2010-2011 Comcast Cable.  All Rights Reserved.
 */
package com.hercules.android.receiver.model.events;

/**
 * <p>
 * This is a subclass of XREEvent that represents error events. It defines some properties specific to these events.
 * Note that values of all custom properties are actually stored in the XREEvent#params map.
 * </p>
 * <p>
 * <strong>Thread safety:</strong> This class is mutable and not thread safe.
 * </p>
 *
 * @author saarixx, jmn
 * @version 1.0
 */
public class XREErrorEvent extends XREResourceEvent {

    /**
     * <p>
     * Represents the name of the "on load failure" event.
     * </p>
     * <p>
     * This is a string constant used by the user when setting the name of the event.
     * </p>
     */
    public static final String ON_ERROR_EVENT_NAME = "onError";

    /**
     * <p>
     * Represents the type of the "on load failure" event.
     * </p>
     * <p>
     * This is a string constant used by the user when setting the name of the event.
     * </p>
     */
    public static final String ERROR_LOAD_FAILED_TYPE = "ERROR_LOAD_FAILED";

    /**
     * <p>
     * Represents the type of the "on connection error" event.
     * </p>
     * <p>
     * This is a string constant used by the user when setting the name of the event.
     * </p>
     */
    public static final String ERROR_CONNECTION_ERROR_TYPE = "ERROR_CONNECTION_ERROR";

    /**
     * Represents the name used to retrieve the type parameter.
     * <p>
     * AndroidAssembly3 changed from 'type' to 'errorType'.
     */
    private static final String ERROR_TYPE = "errorType";

    /**
     * <p>
     * Represents the name used to retrieve the description parameter.
     * </p>
     */
    private static final String DESCRIPTION = "description";

    /**
     * <p>
     * Creates new instance of {@link XREErrorEvent} class.
     * </p>
     */
    public XREErrorEvent() {
        // empty constructor
    }

    /**
     * <p>
     * Retrieves the type of the error.
     * </p>
     *
     * @return the type of the error
     * @throws IllegalStateException if the requested parameter has wrong type in the parameters map or params is null
     */
    public String getErrorType() {
        return getTypedParam(ERROR_TYPE, String.class);
    }

    /**
     * <p>
     * Sets the type of the error.
     * </p>
     *
     * @param errorType the type of the error
     * @throws IllegalStateException if params is null
     */
    public void setErrorType(String errorType) {
        setParam(ERROR_TYPE, errorType);
    }

    /**
     * <p>
     * Retrieves the human readable description of the error.
     * </p>
     *
     * @return the human readable description of the error
     * @throws IllegalStateException if the requested parameter has wrong type in the parameters map or params is null
     */
    public String getDescription() {
        return getTypedParam(DESCRIPTION, String.class);
    }

    /**
     * <p>
     * Sets the human readable description of the error.
     * </p>
     *
     * @param description the human readable description of the error
     * @throws IllegalStateException if params is null
     */
    public void setDescription(String description) {
        setParam(DESCRIPTION, description);
    }
}
